// 该文件专门用于创建整个应用的路由器
// 引入需要的路由
import VueRouter from 'vue-router'
import Login from '../pages/Login.vue'
import Register from '../pages/Register.vue'
import Admin from '../pages/Admin.vue'
import User from '../pages/User.vue'
import Usertable from '../pages/table/Usertable.vue'
import UserInfo from '../pages/table/UserInfo.vue'
import Inoculatetable from '../pages/table/Inoculatetable.vue'
import Ordertable from '../pages/table/Ordertable.vue'
import OnlyInotable from '../pages/table2/OnlyInotable.vue'
import OnlyOrdertable from '../pages/table2/OnlyOrdertable.vue'
import Onlyusertable from '../pages/table2/Onlyusertable.vue'
// 备份原始的push和replace方法
let originPush = VueRouter.prototype.push;
// 重写push
// 第一个参数：告诉原来的push方法往哪跳
// 第二个参数：成功回调
// 第三个参数：失败的回调

VueRouter.prototype.push = function (location, reslove, reject) {
    if (reslove && reject) {
        originPush.call(this, location, reslove, reject);
    } else {
        originPush.call(this, location, () => { }, () => { })
    }
};
// 设置路由
const router = new VueRouter({
    routes: [
        {
            path: '/',
            component: Login,
            redirect: '/login'
        },
        {
            path: '/login',
            component: Login,
        },
        {
            path: '/register',
            component: Register,
        },
        {
            path: '/admin',
            component: Admin,
            children: [
                {
                    path: 'usermanage',
                    component: Usertable,
                },
                {
                    path: 'inoculatemanage',
                    component: Inoculatetable
                },
                {
                    path: 'Ordermanage',
                    component: Ordertable
                },
                {
                    path: 'detail',
                    component: UserInfo
                }
            ]
        },
        {
            path: '/user',
            component: User,
            children: [
                {
                    path: 'inoculate',
                    component: OnlyInotable,
                },
                {
                    path: 'order',
                    component: OnlyOrdertable,

                },
                {
                    path: 'detail',
                    component: Onlyusertable
                }
            ]
        },
    ]
})
export default router;